#ifndef _MINIOS_TRAP_H
#define _MINIOS_TRAP_H

#include <sys/system.h>


#define T_DIVIDE     0		// divide error
#define T_DEBUG      1		// debug exception
#define T_NMI        2		// non-maskable interrupt
#define T_BRKPT      3		// breakpoint
#define T_OFLOW      4		// overflow
#define T_BOUND      5		// bounds check
#define T_ILLOP      6		// illegal opcode
#define T_DEVICE     7		// device not available
#define T_DBLFLT     8		// double fault
/* #define T_COPROC  9 */	// reserved (not generated by recent processors)
#define T_TSS       10		// invalid task switch segment
#define T_SEGNP     11		// segment not present
#define T_STACK     12		// stack exception
#define T_GPFLT     13		// general protection fault
#define T_PGFLT     14		// page fault
/* #define T_RES    15 */	// reserved
#define T_FPERR     16		// floating point error
#define T_ALIGN     17		// aligment check
#define T_MCHK      18		// machine check
#define T_SIMDERR   19		// SIMD floating point error

#define T_SYSCALL   128		// system call
#define T_DEFAULT   500		// catchall


//#define IRQ_OFFSET	32	// IRQ 0 corresponds to int IRQ_OFFSET
// Hardware IRQ numbers. We receive these as (IRQ_OFFSET+IRQ_WHATEVER)
#define IRQ_TIMER        (IRQ0_VECTOR)
#define IRQ_KBD          (IRQ1_VECTOR)
#define IRQ_SERIAL       (IRQ4_VECTOR)
#define IRQ_SPURIOUS     (IRQ7_VECTOR)
#define IRQ_IDE         (IRQ14_VECTOR)
#define IRQ_ERROR	 (IRQ19_VECTOR)


#define FIRST_EXTERNAL_VECTOR           (0x20)
#define IRQ0_VECTOR                     (FIRST_EXTERNAL_VECTOR)
#define IRQ1_VECTOR                     (IRQ0_VECTOR +  1)
#define IRQ2_VECTOR                     (IRQ0_VECTOR +  2)
#define IRQ3_VECTOR                     (IRQ0_VECTOR +  3)
#define IRQ4_VECTOR                     (IRQ0_VECTOR +  4)
#define IRQ5_VECTOR                     (IRQ0_VECTOR +  5)
#define IRQ6_VECTOR                     (IRQ0_VECTOR +  6)
#define IRQ7_VECTOR                     (IRQ0_VECTOR +  7)
#define IRQ8_VECTOR                     (IRQ0_VECTOR +  8)
#define IRQ9_VECTOR                     (IRQ0_VECTOR +  9)
#define IRQ10_VECTOR                     (IRQ0_VECTOR +  10)
#define IRQ11_VECTOR                     (IRQ0_VECTOR +  11)
#define IRQ12_VECTOR                     (IRQ0_VECTOR +  12)
#define IRQ13_VECTOR                     (IRQ0_VECTOR +  13)
#define IRQ14_VECTOR                     (IRQ0_VECTOR +  14)
#define IRQ15_VECTOR                     (IRQ0_VECTOR +  15)
#define IRQ19_VECTOR                     (IRQ0_VECTOR +  19)

// system segment type bits
#define STS_T16A	0x1	    // Available 16-bit TSS
#define STS_LDT		0x2	    // Local Descriptor Table
#define STS_T16B	0x3	    // Busy 16-bit TSS
#define STS_CG16	0x4	    // 16-bit Call Gate
#define STS_TG		0x5	    // Task Gate / Coum Transmitions
#define STS_IG16	0x6	    // 16-bit Interrupt Gate
#define STS_TG16	0x7	    // 16-bit Trap Gate
#define STS_T32A	0x9	    // Available 32-bit TSS
#define STS_T32B	0xB	    // Busy 32-bit TSS
#define STS_CG32	0xC	    // 32-bit Call Gate
#define STS_IG32	0xE	    // 32-bit Interrupt Gate
#define STS_TG32	0xF	    // 32-bit Trap Gate



extern void trap_init();
extern void trap_init_percpu();
extern void print_frame(struct frame *);
#endif/*_MINIOS_TRAP_H*/
